﻿using HealthcareSystem.API.Write.Application.Command.MetricsCommands;
using HealthcareSystem.Domain.BasicSettings.Metrics;
using MediatR;
using Microsoft.AspNetCore.Server.HttpSys;
using WeekExam.PassPort.ErrorCode;
using WeekExam.PassPort.Infrastructure.Interface;

namespace HealthcareSystem.API.Write.Application.CommandHandel.MetricsCommands
{
    public class MetricsCreatedCommandHandler : IRequestHandler<MetricsCreatedCommand, ApiResult<int>>
    {
        private readonly IBaseRepository<Metricss> metssRep;

        public MetricsCreatedCommandHandler(IBaseRepository<Metricss> metssRep)
        {
            this.metssRep = metssRep;
        }

        public async Task<ApiResult<int>> Handle(MetricsCreatedCommand request, CancellationToken cancellationToken)
        {
            ApiResult<int> result=new ApiResult<int>();
            result.Code=ResultCode.Success;
            result.Message=ResultCode.添加成功.ToString();

            Metricss metss=new Metricss();
            metss.MetricsName=request.MetricsName;
            metss.ListofdiseasesId=request.ListofdiseasesId;
            metss.MetricsCode=request.MetricsCode;
            metss.MetricsClassId=request.MetricsClassId;
            metss.IsDeleted = false;
            await metssRep.AddAsync(metss);
            return await Task.FromResult(result);



        }
    }
}
